<?php

namespace app\common\model;

use think\Exception;
use think\Model;

/**
 * 邮箱验证码
 */
class AliPay extends Model
{

    protected $auto = ['ip'];
    protected $table = 'yzn_alipay';
    protected $autoWriteTimestamp = true;

    protected $createTime = 'create_time';


    public function saveAliPay($params)
    {
        try {
            if (!$params['real_name'] || !$params['account']) {
                throw new Exception('缺少参数');
            }
            $account = self::where(['uid' => $params['uid']])->find();
            if ($account) {
                $account->real_name = $params['real_name'];
                $account->account = $params['account'];
            } else {
                $account = new self();
                $account->real_name = $params['real_name'];
                $account->account = $params['account'];
                $account->uid = $params['uid'];
            }

            if (!$account->save()) {
                throw new Exception('提交失败，请重新尝试');
            }

            return ['code' => 200, 'msg' => '提交成功','data'=>''];

        } catch (Exception $e) {
            return ['code' => 201, 'msg' => $e->getMessage()];

        }

    }



    public function getAliPay($params){
        $account = self::where(['uid' => $params['uid']])->find();
        return ['code' => 200, 'msg' => '获取成功','data' => $account];
    }


    public function delAlipay($params){
        $account = self::where(['uid' => $params['uid']])->find();
        if($account->delete()){
            return ['code' => 200, 'msg' => '删除成功'];
        }

        return ['code' => 201, 'msg' => '删除失败，请重新尝试'];
    }


}
